#pragma once

#include <QObject>

#include "Base\AbstractProgressProcedure.h"
#include "Network/Connection.h"

namespace TC
{
	namespace Request
	{
		class TCCORE_EXPORT Downloader : public AbstractProgressProcedure
		{
			Q_OBJECT
				Q_PROPERTY(QByteArray data MEMBER data)
				Q_PROPERTY(QString text READ text)
		public:
			Q_INVOKABLE void download(const QUrl &url);
			Q_INVOKABLE void abort();
		public:
			void onFinished();

			bool isOk();

			void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
		public:
			QString text();
		private:
			QNetworkReply *reply = nullptr;
			QByteArray data;
		};
	}
}